home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group02b.txt / 000043_icon-group-sender_Thu Sep 19 08:22:26 2002.msg < prev    next >
Internet Message Format  |  2003-01-02  |  13KB

  1. Return-Path: <icon-group-sender>
  2. Received: (from root@localhost)
  3.     by baskerville.CS.Arizona.EDU (8.11.1/8.11.1) id g8JFLso23179
  4.     for icon-group-addresses; Thu, 19 Sep 2002 08:21:54 -0700 (MST)
  5. Message-Id: <200209191521.g8JFLso23179@baskerville.CS.Arizona.EDU>
  6. From: "Andrew Hamm" <ahamm@mail.com>
  7. X-Newsgroups: comp.lang.icon
  8. Subject: Re: Icon Wish List
  9. Date: Thu, 19 Sep 2002 12:57:52 +1000
  10. X-Priority: 3
  11. X-MSMail-Priority: Normal
  12. X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
  13. X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
  14. To: icon-group@cs.arizona.edu
  15. Errors-To: icon-group-errors@cs.arizona.edu
  16. Status: RO
  17.  
  18. Frank J. Lhota wrote:
  19. > Looking over the last several versions of Icon, the last several
  20. > versions did little more than adding a few functions and fix a few
  21. > bugs. It has been a while since there have been major enhancements to
  22. > the Icon language. This type of stagnation harms Icon's long term
  23. > prospects. It is time to consider some major upgrades to Icon.
  24. >
  25.  
  26. I've been watching this debate with interest (and am heartened by the
  27. increase in traffic above zero messages a month...) so here's my $0.04(AU)
  28. [current exchange rate is $1.00AU = $0.54US]
  29.  
  30. > 1) Object-Oriented Programming
  31.  
  32. Yes, Idol is very interesting, but I haven't used it in any project, just
  33. dabbled. I have used Icon for a few large tools; 3 of them are an essential
  34. part of the software development production system in my company.
  35.  
  36. The simplest one is a pre-processor in the style of cpp, which we can use
  37. with our 4GL (sql-based) source code. This is a relatively simple process,
  38. and objects could have been convenient to store things like the defines and
  39. the stack of the pre-processor blocks, however lack of OO did not cause any
  40. difficulty.
  41.  
  42. The second major tool is a 4GL code generator. It reads form specification
  43. files, accesses the database for table schema, and generates 4GL. Given the
  44. large number of source instructions representing screen objects and business
  45. rule actions, OO would have been very useful indeed and I did find myself
  46. wishing for classes *with methods* to get around my regular confusion as I
  47. got deep into nasty expressions which could only exploit . and [ ]
  48. operators. Not a few bugs were caused by mistakes with access to deep object
  49. members and performing work on them.
  50.  
  51. The 3rd major tool is a source code merger, which reads a bunch of
  52. instructions to insert, replace or delete code blocks in the generated 4GL
  53. (this allows our programmers to maintain regenerable forms and yet perform
  54. powerful modifications to the generated code, to suit the exact business
  55. needs). This tool exploits the amazing power of coroutines amongst other
  56. things, and I managed to achieve a remarkable O(N) processing time. It's
  57. remarkable because I wrote it to replace a 3rd-party tool which slowed
  58. quadratically vs code size. This process had middling need for OO but once
  59. again exploited the magic of Icon to achieve its task.
  60.  
  61. It's when projects achieve a critical mass that OO becomes a benefit. Any
  62. educational sample of OO fails to prove the need for OO IMHO. I still desire
  63. OO in Icon and forsee no costs beyond the implementation effort. I really
  64. can't see OO degrading Icon; with proper design it should fit in very nicely
  65. and elegantly. Apart from the corruption caused by it's pre-processing
  66. nature, Idol does show what is possible. With integrated support, the rough
  67. edges of Idol could be cleaned up.
  68.  
  69. It's interesting to think about the style of the syntax to use. Given that
  70. OO is only really useful for large projects, I would lean towards the "one
  71. file, one class" approach, which means that the classes could look like
  72. this:
  73.  
  74. <file foo.icl>   # just a suggestion
  75.  
  76. class Foo [ : superclass ... ]
  77.  
  78. define var, var, var ...
  79.  
  80. static classvar, classvar ...
  81.  
  82. constructor Foo( arg ... )
  83.     ....
  84. end
  85.  
  86. destructor ~Foo( )
  87.    # typical destructor stuff
  88. end
  89.  
  90. method instanceMethod( arg ... )
  91.     ...
  92. end
  93.  
  94. static method classMethod( args )
  95.     ...
  96. end
  97.  
  98. </file>
  99.  
  100. NOTE: use of "constructor", "destructor" and "method" keywords does not
  101. denote a preference.
  102.  
  103. Since Icon is completely free with variable types and call arguments, it
  104. follows that class members should not be typed, and overloaded methods do
  105. not make sense either - one name, one method. A class constructor is
  106. obviously needed, and presumably a class destructor too; for the usual
  107. application-level cleanups. Due to the nature of Icon garbage collection,
  108. the destructor would not be called at any predictable time, but then, people
  109. comfortably live with that in Java.
  110.  
  111. There's probably scope for operator overloading. Icon has a decent set of
  112. operators, and some tasks benefit from operator overloading - however,
  113. people do tend to get very silly trying to squeeze as much as possible into
  114. that mould ;)
  115.  
  116. What about member privacy? With the 1 file, 1 class model, it does become
  117. possible to add a "private" keyword for class methods, members and statics.
  118. If marked as private, the member is not visible outside the file. However,
  119. that does not fit at all with the dynamic typing of Icon. How do you know
  120. the type of a particular variable at any one time? You don't, so you can't
  121. block access to specific fields, unless some sort of runtime check was added
  122. to provide the illusion of privacy. Perhaps that's acceptable... If the
  123. runtime check was provided, then presumably protected member access could
  124. also be fitted. Personally I wouldn't fuss deeply about this. The Perlish
  125. idea of the "gentleperson's agreement" works for me.
  126.  
  127. Should member variables be accessible with the usual . notation? Or should
  128. objects *only* allow either readonly access to variables, with all
  129. assignments applied only in the class source file? Presumably, identifiers
  130. would be looked up thru the local declarations (and method args) then class
  131. variables, then finally globals. So it could be reasonable to say that
  132. Obj.varname is simply not assignable. Very easy. However, that would make
  133. even classes suspicious of themself:
  134.  
  135. class Foo;
  136.  
  137. define Bar;
  138.  
  139. method Baz( )
  140.     local other
  141.  
  142.     other := expression-yielding-Foo-object
  143.     other.Bar := 1    # ERROR!!!!! dang
  144.     other.setBar(1)  # works, but ugly
  145. end
  146.  
  147. Hence, I would keep away from that and invoke the Gentlecodesters agreement
  148. again...
  149.  
  150. With the current Icon runtime, the interpretation of obj.member would
  151. actually need to resolve to an internal object just like the pending array
  152. (or is it string?) assignments (sorry, my implementation book is at home and
  153. it's been 5 years since I last read it anyway). Since obj.field (and indeed
  154. obj[index]) could be variously interpreted as
  155.  
  156.     rec.field, or
  157.     class.field, or
  158.     class.static, or
  159.     class.method
  160.  
  161. depending in the dynamic type of obj, the . operator in the runtime would
  162. need extending so that if the left arg is an object, the field is looked up
  163. via the class. If the field is found as a member variable, then it probably
  164. could yield an assignable item just like rec.field, but if the field is
  165. found to be a method, then it should yield a new variant on the proc - a
  166. special block which also records the sender. In theory, it's entirely
  167. possible to pass this thing around before using it:
  168.  
  169.     mc := obj.method
  170.     foo(mc)
  171.     ....
  172. procedure foo(mc)
  173.     x := mc(arg1, arg2)
  174.  
  175. Simply because obj.method needs to have ( ) stuffed on the end before the
  176. actual call is applied. In normal practice of course, that is what would
  177. usually happen:
  178.  
  179.     val := obj.method(arg1, arg2)
  180.  
  181. but the internal implentation is simple and interesting because of it.
  182.  
  183. What else? Inheritance? OK...
  184.  
  185. Sure, multiple inheritance. Circular like Idol? Why not! Very interesting
  186. idea and I don't see why the compiler needs to drown in a sea of infinite
  187. recursion if decent programmers work on it ;-) What about if two supers have
  188. the same super, leading to a diamond structure?
  189.  
  190. class A
  191. class B : A
  192. class C : A
  193. class D : B C
  194.  
  195. What did Idol do? Merge? I don't remember. But Idol is probably a good
  196. guide. How's this for an alternative: Since OO is best for large projects,
  197. the Eiffel concept of "redefine" and "rename" are very appealing. Not only
  198. do these two clauses eliminate most of the anti-multiple inheritance
  199. arguments, it also solves a less talked-about problem, where a parent class
  200. might be extended by adding a new method or member, which subsequently
  201. conflicts silently with a subclass member of the same name. There is
  202. responsibility in this direction also...
  203.  
  204. The redefine and rename clauses eliminate the need for messy syntax which is
  205. needed to access overridden parent members. If they are overridden they can
  206. be made available through a different name so there is no need for nonsense
  207. like super::method( ... ).
  208.  
  209. With the rename and redefine clauses, you are expected to know and declare
  210. redefinitions. In large projects, that's a very powerful safety feature. How
  211. could this work in Objective Icon? The compiler will collect a class
  212. definition. An optional list of parent classes might be found, with optional
  213. redefine or rename clauses, along with member variables and methods. The
  214. compiler would collect all these items in good faith, and build the
  215. intermediate code as it does now, assuming that the linker and runtime will
  216. make more sense of it all.
  217.  
  218. The linker would then take on a greater role. All the class definitions need
  219. to be banged together; insert Tab A into Slot B and so on. At this point,
  220. the inheritance trees (graphs) will be constructed. I would propose that
  221. each class definition will have a private member list built, so that the
  222. runtime system does not need to travel the tree each time a member is
  223. accessed. A simple lookup of the member in the objects class will be
  224. sufficient to find it's offset within the object and it's type etc.
  225.  
  226. Back to the class traversal: For each class, visit all the parents looking
  227. for extra members and methods to attach to the class. Any conflicts which
  228. are in violation of the rename and redefine clauses can be found at this
  229. time. Therefore the class tree could be shown to be correct by the linker.
  230. By this time, everything is resolved, the final .icx is written and we're
  231. ready for the real fun to begin.
  232.  
  233. Is that enough? I've proposed something very simple, requiring only a few
  234. new internal block types to represent the classes, the objects, and the
  235. mutated proc blocks (sender.method). I've relied upon a Gentle-programmers
  236. agreement for all the usual fuss about protection, encapsulation etc.
  237. Runtime traversals to find methods can be avoided.
  238.  
  239. What about abstract classes and abstract methods? What about them? I suppose
  240. they are possible; in fact, a redefine clause without a corresponding method
  241. definition will implicitly be an abstract method. Is this any use? I would
  242. guess that an abstract method would merely be a null member in the class
  243. lookup table. Icon currently supports this (and provides a runtime error) if
  244. you attempt a call to a non-existent method. This is probably a very
  245. appropriate response for OO too.
  246.  
  247. > 2) Better Interfacing to External Programs
  248. >
  249. >[SNIP]
  250. >
  251. > Nevertheless, other languages provide ways of calling external
  252. > functions and handling external memory. Why can't Icon have these
  253. > abilities?
  254. >
  255.  
  256. Why not indeed? Perl's XS facility does a very good job. Of course, the C
  257. code must comply. Perl does offer a usable malloc and free which means it's
  258. quite easy to link in 3rd party libraries which may not assume they'll be
  259. linked into Perl. Icon/XS will need the same respect for 3rd-party
  260. libraries. The XS framework generator is a very useful tool for Perl, and
  261. points to the need for something similar with Icon.
  262.  
  263. > 3) Unicode Support
  264. >
  265.  
  266. Don't care ;-) I guess we should all get into the 21st century sooner or
  267. later...
  268.  
  269. > 4) Icon as a Scripting Language
  270. >
  271.  
  272. Interesting idea. In principle, some simple hack can already be done using
  273. hash-bang lines and possibly a bit of disguised shell-code. Isn't there an
  274. icont argument which asks for automatic execution of the resulting object?
  275. If there isn't it can surely be added.
  276.  
  277. To do this "properly" on UNIX, the compiler could probably write to a tmp
  278. file (not linked into a directory) and then hand the open file handles off
  279. to a cooperating iconx which can slurp up the icode from the tmp file
  280. handles and then close them, resulting in their deallocation. This is a very
  281. simple improvement to the compiler and runner, and I wouldn't really class
  282. this as an extension to Icon, because it's more mechanical than anything
  283. else.
  284.  
  285.  
  286.  
  287.